07. Helping the Robot for Real!
Prepare
Take another look at moveSimpleRobot in the ControlCenter.swift file. This is the only portion of code you need to worry about for now. For this exercise, all the code you want to write will be here.
Learn
Right now, the robot understands four instructions:
robot.moveUp()
robot.moveDown()
robot.moveRight()
robot.moveLeft()
Your mission is to write the Swift code that moves the robot to the star. Since we’ve written the algorithm ahead of time, this should be pretty easy. As you write your instructions, check the progress of the robot by running the application.
If your robot gets stuck, coaches and students are fielding questions on the forum and ready to help!
Reflect
Once the robot reaches the star, you should see a completion code printed in the Debug area. If the Debug area is not showing the left and right panels, click the icons in the lower right-hand corner next to the garbage can icon.
Completion Code
The completion code is shown in the Debug area.
Completion Code
QUESTION:
What is the completion code? If the Debug area does not appear after the robot reaches the star, try show/hiding the Debug area with the buttons we used earlier.
ANSWER:
You should have seen the code: Ud@c1ty. Congratulations if you got it!
A New Robot Challenge
Prepare
For this exercise, we are going to use a different, more complex robot with a new set of commands. This new robot has a forward direction, and we will need to rotate the robot in the direction we want before moving it forward. The robot understands the following instructions:
New Robot Moves
This robot has a new set of moves.
Switching Projects
To get started, close your current Xcode project and open the Xcode project in the Maze-ComplexRobot directory. If you cannot find this directory, then try re-downloading the project files for the Maze app.
Learn
Like the previous exercises, we will go back to our familiar friend the ControlCenter.swift file. This time we will be working in moveComplexRobot.
Move Complex Robot
To move the complex robot about the maze, we'll use moveComplexRobot.
Here
Here, you can write code to guide the robot to the star using its new moves!
Robot Solution
QUESTION:
In moveComplexRobot, write a sequence of steps that moves the robot to the star using only rotateLeft, rotateRight, move, and move (with some number of steps).
ANSWER:
Reflect
QUESTION:
This is just the beginning of your journey to becoming an iOS developer. What is your biggest takeaway from the kickoff? What are you looking forward to learning?
ANSWER:
Thanks for sharing your thoughts. We really hope you are as excited to learn as we are to teach!
Congratulations!